﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using COFE.Core.Utils;
using COFE.Core;

namespace COFE.Web
{    
    /// <summary>
    /// Represent the type of an entry (File or Folder).
    /// </summary>
    public enum EntryBaseType : int
    {
        Unknown = 0,
        File,
        Folder
    }

    /// <summary>
    /// Extends EntryBaseType.
    /// </summary>
    public static class EntryTypeExtension
    {
        /// <summary>
        /// Parse EntryBaseType string ("File" or "Folder") to EntryBaseType.
        /// </summary>
        /// <param name="entryString"></param>
        /// <returns></returns>
        public static EntryBaseType Parse(string entryString)
        {
            try
            {
                EntryBaseType entryType = (EntryBaseType)Enum.Parse(typeof(EntryBaseType), entryString, true);
                return entryType;
            }
            catch
            {
                return EntryBaseType.Unknown;
            }
        }

        /// <summary>
        /// Convert COFEEntry type to EntryBaseType.
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        public static EntryBaseType FromCOFE(IFileSystemInfo entry)
        {
            if (entry is IFileInfo)
                return EntryBaseType.File;
            if (entry is IDirectoryInfo)
                return EntryBaseType.Folder;
            return EntryBaseType.Unknown;
        }
    }
}
